home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
shadowfile.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-02-17
|
32KB
|
844 lines
;;; shadowfile.el --- automatic file copying for Emacs 19
;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
;; Keywords: comm
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; LCD Archive Entry:
;; shadowfile|Boris Goldowsky|boris@gnu.ai.mit.edu|
;; Helps you keep identical copies of files in multiple places.|
;; $Date: 1996/01/25 01:16:55 $ |$Revision: 1.8 $|~/misc/shadowfile.el.Z|
;; Commentary:
;; This package helps you to keep identical copies of files in more than one
;; place - possibly on different machines. When you save a file, it checks
;; whether it is on the list of files with "shadows", and if so, it tries to
;; copy it when you exit emacs (or use the shadow-copy-files command).
;; Installation & Use:
;; Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
;; and file groups with shadow-define-cluster,
;; shadow-define-literal-group, and shadow-define-regexp-group (see the
;; documentation for these functions for information on how and when to
;; use them). After doing this once, everything should be automatic.
;; The lists of clusters and shadows are saved in a file called .shadows,
;; so that they can be remembered from one emacs session to another, even
;; (as much as possible) if the emacs session terminates abnormally. The
;; files needing to be copied are stored in .shadow_todo; if a file cannot
;; be copied for any reason, it will stay on the list to be tried again
;; next time. The .shadows file should itself have shadows on all your
;; accounts so that the information in it is consistent everywhere, but
;; .shadow_todo is local information and should have no shadows.
;; If you do not want to copy a particular file, you can answer "no" and
;; be asked again next time you hit C-x 4 s or exit emacs. If you do not
;; want to be asked again, use shadow-cancel, and you will not be asked
;; until you change the file and save it again. If you do not want to
;; shadow that file ever again, you can edit it out of the .shadows
;; buffer. Anytime you edit the .shadows buffer, you must type M-x
;; shadow-read-files to load in the new information, or your changes will
;; be overwritten!
;; Bugs & Warnings:
;;
;; - It is bad to have two emacses both running shadowfile at the same
;; time. It tries to detect this condition, but is not always successful.
;;
;; - You have to be careful not to edit a file in two locations
;; before shadowfile has had a chance to copy it; otherwise
;; "updating shadows" will overwrite one of the changed versions.
;;
;; - It ought to check modification times of both files to make sure
;; it is doing the right thing. This will have to wait until
;; file-newer-than-file-p works between machines.
;;
;; - It will not make directories for you, it just fails to copy files
;; that belong in non-existent directories.
;;
;; Please report any bugs to me (boris@gnu.ai.mit.edu). Also let me know
;; if you have suggestions or would like to be informed of updates.
;;; Code:
(provide 'shadowfile)
(require 'ange-ftp)
(setq find-file-visit-truename t) ; makes life easier with symbolic links
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar shadow-noquery nil
"*If t, always copy shadow files without asking.
If nil \(the default), always ask. If not nil and not t, ask only if there
is no buffer currently visiting the file.")
(defvar shadow-inhibit-message nil
"*If nonnil, do not display a message when a file needs copying.")
(defvar shadow-inhibit-overload nil
"If nonnil, shadowfile won't redefine C-x C-c.
Normally it overloads the function `save-buffers-kill-emacs' to check
for files have been changed and need to be copied to other systems.")
(defvar shadow-info-file nil
"File to keep shadow information in.
The shadow-info-file should be shadowed to all your accounts to
ensure consistency. Default: ~/.shadows")
(defvar shadow-todo-file nil
"File to store the list of uncopied shadows in.
This means that if a remote system is down, or for any reason you cannot or
decide not to copy your shadow files at the end of one emacs session, it will
remember and ask you again in your next emacs session.
This file must NOT be shadowed to any other system, it is host-specific.
Default: ~/.shadow_todo")
;;; The following two variables should in most cases initialize themselves
;;; correctly. They are provided as variables in case the defaults are wrong
;;; on your machine \(and for efficiency).
(defvar shadow-system-name (system-name)
"The complete hostname of this machine.")
(defvar shadow-homedir nil
"Your home directory on this machine.")
;;;
;;; Internal variables whose values are stored in the info and todo files:
;;;
(defvar shadow-clusters nil
"List of host clusters \(see shadow-define-cluster).")
(defvar shadow-literal-groups nil
"List of files that are shared between hosts.
This list contains shadow structures with literal filenames, created by
shadow-define-group.")
(defvar shadow-regexp-groups nil
"List of file types that are shared between hosts.
This list contains shadow structures with regexps matching filenames,
created by shadow-define-regexp-group.")
;;;
;;; Other internal variables:
;;;
(defvar shadow-files-to-copy nil) ; List of files that need to
; be copied to remote hosts.
(defvar shadow-hashtable nil) ; for speed
(defvar shadow-info-buffer nil) ; buf visiting shadow-info-file
(defvar shadow-todo-buffer nil) ; buf visiting shadow-todo-file
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Syntactic sugar; General list and string manipulation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmacro shadow-when (condition &rest body)
;; From cl.el
"(shadow-when CONDITION . BODY) => evaluate BODY if CONDITION is true."
(` (if (not (, condition)) () (,@ body))))
(defun shadow-union (a b)
"Add members of list A to list B
if they are not equal to items already in B."
(if (null a)
b
(if (member (car a) b)
(shadow-union (cdr a) b)
(shadow-union (cdr a) (cons (car a) b)))))
(defun shadow-find (func list)
"If FUNC applied to some element of LIST is nonnil,
return the first such element."
(while (and list (not (funcall func (car list))))
(setq list (cdr list)))
(car list))
(defun shadow-remove-if (func list)
"Remove elements satisfying FUNC from LIST.
Nondestructive; actually returns a copy of the list with the elements removed."
(if list
(if (funcall func (car list))
(shadow-remove-if func (cdr list))
(cons (car list) (shadow-remove-if func (cdr list))))
nil))
(defun shadow-join (strings sep)
"Concatenate elements of the list of STRINGS with SEP between each."
(cond ((null strings) "")
((null (cdr strings)) (car strings))
((concat (car strings) " " (shadow-join (cdr strings) sep)))))
(defun shadow-regexp-superquote (string)
"Like regexp-quote, but includes the ^ and $
to make sure regexp matches nothing but STRING."
(concat "^" (regexp-quote string) "$"))
(defun shadow-suffix (prefix string)
"If PREFIX begins STR